'use strict';
const webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const chalk = require('chalk');

const webpackConfig = require('../config/dev.config');


const defaultServerConfig = {
    port: 8001,
    host: require('ip').address()
}
const ServerConfig = {
    ...defaultServerConfig,
    ...webpackConfig.devServer
}

new WebpackDevServer(webpack(webpackConfig), webpackConfig.devServer)
    .listen(ServerConfig.port, ServerConfig.host, (err) => {
        if(err){
            console.log('启动异常');
            console.error(err);
        }else{
            console.log(chalk.blue(' # Access URLs:'));
            console.log(chalk.gray(' ----------------------------------------'));
            console.log('     Local: ' + chalk.green('http://localhost:' + ServerConfig.port));
            console.log('  External: ' + chalk.green('http://' + ServerConfig.host + ':' + ServerConfig.port));
            console.log(chalk.gray(' ----------------------------------------'));
            console.log('');
        }        
    });